/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package project_temple.client;

/**
 *
 * @author STARTHERE
 */
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;

public class clientHandler extends Thread{

    private Socket socket;
    private String com;
    public clientHandler(Socket socket, String com) {
        this.socket = socket;
        this.com = com;
    }
    public void send(String com){
        try {
            DataOutputStream out = new DataOutputStream(socket.getOutputStream());
            out.writeUTF(com);
        } catch (IOException ex) {
            Logger.getLogger(clientHandler.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    public String receive(){
        String result = null;
        try {
            try {
                Thread.sleep(300);
            } catch (InterruptedException ex) {
                Logger.getLogger(clientHandler.class.getName()).log(Level.SEVERE, null, ex);
            }
            DataInputStream in = new DataInputStream(socket.getInputStream());
            result=in.readUTF();
        } catch (IOException ex) {
            Logger.getLogger(clientHandler.class.getName()).log(Level.SEVERE, null, ex);
        }
        return result;
    }

    @Override
    public void run(){
        clientHandler cl=new clientHandler(socket,com);
        cl.send(com);
        try {
            Thread.sleep(300);
        } catch (InterruptedException ex) {
            Logger.getLogger(clientHandler.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
